package org.example.demo17_responsibility;

public abstract class Handler {
    protected final static int NUM_ONE = 10000;
    protected final static int NUM_FIVE = 50000;
    protected final static int NUM_TEN = 100000;
    protected final static int NUM_TWENTY = 200000;

    private int numStart;
    private int numEnd;
    private Handler nextHandler;

    public Handler(int numStart){
    this.numStart = numStart;
    }
    public Handler(int numStart, int numEnd){
        this.numStart = numStart;
        this.numEnd = numEnd;
    }
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }
    protected abstract void handlerRequest(PurchaseOrder purchaseOrder);

    public final void submit(PurchaseOrder purchaseOrder){
        this.handlerRequest(purchaseOrder);
        if(this.nextHandler!= null && purchaseOrder.getPrice() >= this.numEnd){
            this.nextHandler.submit(purchaseOrder);
        }else {
            System.out.println("流程结束");
        }
    }
}
